<template>
    <div class="collect-page">
        <!-- Header组件 -->
        <Header>
            <template v-slot:left>
                <span @click="$router.go(-1)">&lt;</span>
            </template>
            <template v-slot:middle>
                我的收藏
            </template>
        </Header>

        <!-- 收藏列表 -->
        <div class="list" v-if="collectList.length > 0">
            <router-link :to="{name:'detail',params:{item}}" class="item" v-for="(item,index) in collectList" :key="index">
                <div class="pic">
                    <img :src="item.pic" alt="">
                </div>
                <div class="text">
                    <div class="name">{{item.name}}</div>
                    <div>月售 {{item.buyCount}}</div>
                    <div>描述 {{item.desc}}</div>
                </div>
            </router-link>
        </div>
        <div class="empty" v-else>您还没有收藏任何店铺!</div>
    </div>
</template>

<script>

//mapState 将当前组件和vuex关联起来,负责将数据注入到当前组件.
import { mapState } from 'vuex'

export default {
    data(){
        return {

        }
    },
    computed:{
        ...mapState(['collectList'])
    }
}
</script>
<style scoped>
.list .item{
  text-decoration: none;
  color: #333;
  display: flex;
  margin: 20px;
}
.list .item .pic{
  width: 70px;
  margin-right: 20px;
}
.list .item .pic img{
  width: 100%;
}
.list .item .text{
  font-size: 14px;
  flex: 1;
}
.list .item .text .name{
  font-weight: bold;
  font-size: 18px;
  margin-bottom: 10px;
}

.empty{
    text-align: center;
    padding: 50px 0;
    color: #333;
}
</style>